package com.hunau.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hunau.mapper.UsersMapper;
import com.hunau.pojo.Element;
import com.hunau.pojo.Menu;
import com.hunau.pojo.Url;
import com.hunau.pojo.Users;
import com.hunau.service.ElementService;
import com.hunau.service.MenuService;
import com.hunau.service.UrlService;
import com.hunau.service.UsersService;

@Service
public class UsersServiceImpl implements UsersService {
	@Resource
	private UsersMapper usersMapper;
	@Resource
	private MenuService menuServiceImpl;
	@Resource
	private ElementService elementServiceImpl;
	@Resource
	private UrlService urlServiceImpl;

	@Override
	public Map<String, Object> login(Users users) {
		// TODO Auto-generated method stub
		HashMap<String, Object> map = new HashMap<>();
		Users user = usersMapper.selByUser(users);
		if (user != null) {
			List<Menu> menus = menuServiceImpl.showMenu(user.getRid());
			user.setMenus(menus);
			List<Element> elements = elementServiceImpl.selByRid(users.getRid());
			user.setElements(elements);
			List<Url> urls = urlServiceImpl.selByRid(user.getRid());
			user.setUrls(urls);
			List<Url> showAll = urlServiceImpl.showAll();
			map.put("allurl", showAll);
		}
		map.put("user", user);
		return map;
	}

}
